package Controller;

import Service.impl.OrderDetailsServiceImpl;
import com.alibaba.fastjson.JSON;
import org.omg.PortableInterceptor.INACTIVE;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class PriceSumComputeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        //获取传递参数
        String startDateGet = request.getParameter("startDate");
        String endDateGet = request.getParameter("endDate");
        String room_of_numGet = request.getParameter("room_of_num");
        String roomIdGet=request.getParameter("roomId");
        //转型
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date startDate=dateFormat.parse(startDateGet);
            Date endDate=dateFormat.parse(endDateGet);
            Integer roomOfNum=Integer.parseInt(room_of_numGet);
            Integer roomId=Integer.parseInt(roomIdGet);
            //去业务层
            OrderDetailsServiceImpl orderDetailsService=new OrderDetailsServiceImpl();
            Integer resultSum=orderDetailsService.priceSum(startDate,endDate,roomOfNum,roomId);
            response.getWriter().print(JSON.toJSONString(resultSum));
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
